<?php

class PromoteAction extends CommonAction
{

    public function _initialize() {
        parent::_initialize();
        C('LAYOUT_NAME', 'Layout/columns-left');
    }

    public function index() {
        /**
         * 獲取分類
         */
        $identify = $this->_get('category');
        $categoryModel = M('Category');
        $map = array();
        $map['language'] = $this->language;
        if($identify) {
            $map['identify'] = $identify;
            $category = $categoryModel->where($map)->find();
        } else {
            $map['parent_id'] = 5;
            $category = $categoryModel->where($map)->order('position asc')->find();
        }
        
        $this->assign('category',$category);
        /**
         * 獲取產品
         */
        
        import("@.ORG.Util.Page");       //导入分页类
        $modelProduct = M('Promote');
        $mapProduct = array();
        $mapProduct['language'] = $this->language;
        $mapProduct['category_id'] = $category['category_id'];
        $count = $modelProduct->where($mapProduct)->count();    //计算总数

        $p = new Page($count, 2);
        $rows = $modelProduct
                ->where($mapProduct)
                ->limit($p->firstRow . ',' . $p->listRows)
                ->order('promote_id desc')
                ->select();

        $p->SetPager('zjj', 
                '<div class="newpager">{prev}{list}{next}</div>', 
                array(
                    "listlong" => "6", 
                    "first" => "<<", 
                    "last" => ">>", 
                    "prev" => "<", 
                    "next" => ">", 
                    "list" => "*", 
                    "jump" => "select"));
        $page = $p->show('zjj');            //分页的导航条的输出变量
        $this->assign("page", $page);
        $this->assign("rows", $rows); //数据循环变量
        $this->display('index');
    }


}